package leetcode.offer;

/**
 * ClassName: Offer21_Exchange
 * Description: leetcode-剑指offer 21 调整数组顺序使奇数位于偶数前面
 * date: 2021-11-09 10:51
 *
 * @author liyifan
 */
public class Offer21_Exchange {
    public int[] exchange(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        while (left < right) {
            while (left < right && (nums[left] & 1) == 1)
                left++;

            while (left < right && (nums[right] & 1) == 0)
                right--;

            int temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;
        }
        return nums;
    }

}
